/*
* @Author: tomystery
* @Date:   2017-10-08 15:49:10
* @Last Modified by:   tomystery
* @Last Modified time: 2017-10-08 22:07:24
*/
'use strict';
require('./index.css');
require('page/common/nav/index.js');
require('page/common/header/index.js');
var templateIndex=require('./index.string');
var _mm=require('util/mm.js');
var _payment=require('service/payment-service.js');
//page逻辑部分
var page={
	data:{
		orderNumber:_mm.getUrlParam('orderNumber')
	},
	init:function(){
		this.onLoad();
		this.bindEvent();
	},
	onLoad:function(){

		
		this.loadPaymentInfo();

		
	},
	loadPaymentInfo:function(){
		var _this=this;
		var $pageWrap=$('.page-wrap');
		$pageWrap.html('<p class="loading"></p>')
		_payment.getPaymentInfo(this.data.orderNumber,function(res){
			
			//渲染
			var paymentHtml=_mm.renderHtml(templateIndex,res);
				
			 $pageWrap.html(paymentHtml);
			//添加一个监听订单状态的
			_this.listenOrderStatus();


		},function(errMsg){
			$pageWrap.html('<p class="err-tip">'+errMsg+'</p>');

		})



	},
	//监听订单状态
	listenOrderStatus:function(){
	var _this=this;
	this.paymentTimer=window.setInterval(function(){
		_payment.getPaymentStatus(_this.data.orderNumber,function(res){
			console.log(res);
			if(res==true){
				window.location.href='./result.html?type=payment&orderNumber='+_this.data.orderNumber;
			}

		})

},5e3);
	},
	
	bindEvent:function(){
		var _this=this;
		
	},
	   
	
};
	

$(function(){
	page.init();
})
